home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Lib / DTS.Lib.headers / Utilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  34.5 KB  |  809 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Collection of Utilities for DTS Sample code
  6. #
  7. #    Program:    Utilities.c.o
  8. #    File:        Utilities.h    -    Header for C Source
  9. #
  10. #    Copyright © 1988-1990 Apple Computer, Inc.
  11. #    All rights reserved.
  12. #
  13. -----------------------------------------------------------------------------------------*/
  14.  
  15. #ifndef __UTILITIES__
  16. #define __UTILITIES__
  17.  
  18. #ifdef applec
  19.  
  20. #    ifndef __TYPES__
  21. #        include <Types.h>
  22. #    endif
  23.  
  24. #    ifndef __QUICKDRAW__
  25. #        include <QuickDraw.h>
  26. #    endif
  27.  
  28. #    ifndef __DIALOGS__
  29. #        include <Dialogs.h>
  30. #    endif
  31.  
  32. #    ifndef __FILES__
  33. #        include <Files.h>
  34. #    endif
  35.  
  36. #    ifndef __MEMORY__
  37. #        include <Memory.h>
  38. #    endif
  39.  
  40. #    ifndef __MENUS__
  41. #        include <Menus.h>
  42. #    endif
  43.  
  44. #    ifndef __OSUTILS__
  45. #        include <OSUtils.h>
  46. #    endif
  47.  
  48. #    ifndef __WINDOWS__
  49. #        include <Windows.h>
  50. #    endif
  51.  
  52. #endif
  53.  
  54.  
  55. #include "UtilitiesCommon.h"
  56. #ifndef __STRINGUTILS__
  57. #include "StringUtils.h"
  58. #endif
  59.  
  60.  
  61. struct PopupCtlData {
  62.     MenuHandle        mHandle;
  63.     short            mID;
  64.     char            mPrivate[1];
  65. };
  66. typedef struct PopupCtlData PopupCtlData;
  67. typedef PopupCtlData *PopupCtlDataPtr, **PopupCtlDataHandle;
  68. #define    kMenuItemTxtInsert    -1
  69. #define    kMenuItemNumInsert    -2
  70. #define kMenuItemSectionEnd    -3
  71.  
  72. /*-----------------------------------------------------------------------------------------
  73.     Global constants
  74. -----------------------------------------------------------------------------------------*/
  75. #ifndef applec
  76.  
  77. #ifndef nil
  78. #define nil    0L
  79. #endif
  80.  
  81. #ifndef _WaitNextEvent
  82. #define _WaitNextEvent    0xA860
  83. #endif
  84.  
  85. #ifndef _InitGraf
  86. #define _InitGraf        0xA86E
  87. #endif
  88.  
  89. #ifndef _Unimplemented
  90. #define _Unimplemented    0xA89F
  91. #endif
  92.  
  93. /*
  94. #define screenActive            15
  95. */
  96. #endif
  97.  
  98. #define    kNoEvents                0            /* no events mask */
  99. #define kDelayTime                8            /* For the delay time when flashing the
  100.                                                menubar and highlighting a button.
  101.                                                8/60ths of a second*/
  102.  
  103. #define kStartPtH                2            /* offset from the left of the screen */
  104. #define kStartPtV                2            /* offset from the top of the screen */
  105. #define kStaggerH                12            /* staggering amounts for new windows */
  106. #define kStaggerV                16
  107.  
  108. #define chHome                    '\001'        /* ASCII code for the Home key */
  109. #define chEnter                    '\003'        /* ASCII code for Enter character */
  110. #define chEnd                    '\004'        /* ASCII code for the End key */
  111. #define chHelp                    '\005'        /* ASCII code for Help key */
  112. #define chBackspace                '\010'        /* ASCII code for Backspace character */
  113. #define chTab                    '\011'        /* ASCII code for Tab character */
  114. #define chPageUp                '\013'        /* ASCII code for Page Up key */
  115. #define chPageDown                '\014'        /* ASCII code for Page Down key */
  116. #define chReturn                '\015'        /* ASCII code for Return character */
  117. #define chFunction                '\020'        /* ASCII code for any function key */
  118. #define chClear                    '\033'        /* ASCII code for Clear key (aka ESC) */
  119. #define chEscape                '\033'        /* ASCII code for Escape (aka Clear) key */
  120. #define chLeft                    '\034'        /* ASCII code for left arrow */
  121. #define chRight                    '\035'        /* ASCII code for right arrow */
  122. #define chUp                    '\036'        /* ASCII code for up arrow */
  123. #define chDown                    '\037'        /* ASCII code for down arrow */
  124. #define chFwdDelete                '\177'        /* ASCII code for forward delete */
  125. #define chSpace                    ' '            /* ASCII code for Space character */
  126.  
  127. enum { kQDOriginal = 0, kQD8Bit, kQD32Bit };    /* For use with gQDVersion */
  128.  
  129. /*-----------------------------------------------------------------------------------------
  130.     Types
  131. -----------------------------------------------------------------------------------------*/
  132.  
  133. typedef short *IntegerPtr, **IntegerHandle;
  134.  
  135. typedef long *LongintPtr, **LongintHandle;
  136.  
  137. typedef Boolean *BooleanPtr, **BooleanHandle;
  138.  
  139. #ifndef THINK_C
  140. typedef Rect *RectPtr, **RectHandle;
  141. #endif
  142.  
  143. struct    WindowTemplate    {                    /*template to a WIND resource*/
  144.     Rect    boundsRect;
  145.     short    procID;
  146.     Boolean    visible;
  147.     Boolean    filler1;
  148.     Boolean    goAwayFlag;
  149.     Boolean    filler2;
  150.     long    refCon;
  151.     Str255    title;
  152. };
  153. typedef    struct    WindowTemplate    WindowTemplate;
  154. typedef            WindowTemplate    *WindowTPtr, **WindowTHndl;
  155.  
  156. /* following is here to account for lapses in the THINK C headers */
  157.  
  158. #ifndef applec
  159. #ifndef THINK_C
  160. /*
  161. typedef unsigned char TrapType;
  162. */
  163. struct NumVersion {
  164.     unsigned char majorRev;         /* 1st part of version number in BCD*/
  165. /*    unsigned short minorRev : 4;        2nd part is 1 nibble in BCD*/
  166. /*    unsigned short bugFixRev : 4;         3rd part is 1 nibble in BCD*/
  167.     unsigned char minorAndBugFixRev;
  168.     unsigned char stage;            /*stage code: dev, alpha, beta, final*/
  169.     unsigned char nonRelRev;        /*revision level of non-released version*/
  170. };
  171.  
  172. typedef struct NumVersion NumVersion;
  173. /* Numeric version part of 'vers' resource */
  174. struct VersRec {
  175.     NumVersion numericVersion;        /*encoded version number*/
  176.     short countryCode;                /*country code from intl utilities*/
  177.     Str255 shortVersion;            /*version number string - worst case*/
  178.     Str255 reserved;                /*longMessage string packed after shortVersion*/
  179. };
  180. typedef struct VersRec VersRec;
  181. typedef VersRec *VersRecPtr, **VersRecHndl;
  182.  
  183.  
  184. #define Length(string) (*(unsigned char *)(string))
  185. #define Gestalt            GESTALT
  186. #define NewGestalt        NEWGESTALT
  187. #define ReplaceGestalt    REPLACEGESTALT
  188. #endif
  189. #endif
  190.  
  191.  
  192. typedef Rect (*PositionWndProcPtr)(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  193.  
  194.  
  195. typedef struct PFSSpec {
  196.     FSSpec    fss;
  197.     Str31    volName;
  198. } PFSSpec;
  199. typedef PFSSpec *PFSSpecPtr;
  200.  
  201.  
  202. /*-----------------------------------------------------------------------------------------
  203.     Handy Macros/inlines
  204. -----------------------------------------------------------------------------------------*/
  205. #ifdef false                                        /* The c++ stuff is turned OFF!!! */
  206.  
  207. inline Point* TopLeft(Rect& r)                        /* provide access to rect.topLeft  */
  208. {    return (Point*)(&r.top); }
  209.  
  210. inline Point* BotRight(Rect& r)                        /* provide access to rect.botRight  */
  211. {    return (Point*)(&r.bottom); }
  212.  
  213. inline short HiWrd(long aLong)                        /* return the hi word of a long */
  214. {    return ((aLong >> 16) & 0xFFFF); }
  215.  
  216. inline short LoWrd(long aLong)                        /* return the lo word of a long */
  217. {    return (aLong & 0xFFFF); }
  218.  
  219. inline void SETPT(Point *pt,short h,short v)
  220. {    (*pt).h = h; (*pt).v = v); }
  221.  
  222. inline void SETRECT(Rect *r,short left,short top,short right,short bottom)
  223. {    SETPT(TopLeft(*r), left, top); SETPT(BotRight(*r), right, bottom); }
  224.  
  225. /* 
  226.  *    Useful functions for testing gestalt attribute responses
  227.  *
  228.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  229.  *    BTstQ which simply returns a non-zero value if the bit is set which
  230.  *    means the result could get lost if assigned to a short, for example.
  231.  *
  232.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  233.  *    bitnbr = 0 is the least significant bit.
  234.  */
  235. inline short BTstBool(arg, bitnbr)    
  236. {    return ((arg >> bitnbr) & 1); }
  237.  
  238. inline long BTstQ(arg, bitnbr)
  239. {    return (arg & (1 << bitnbr)); }
  240.  
  241. #else
  242.  
  243.  
  244. #ifndef THINK_C
  245. #define QD(whatever) (qd.##whatever)
  246. #else
  247. #define QD(whatever) (whatever)
  248. #endif
  249.  
  250.  
  251. #define TopLeft(r)        (* (Point *) &(r).top)
  252. #define BotRight(r)        (* (Point *) &(r).bottom)
  253. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  254. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  255. #define MIN(a, b) ((a) < (b) ? (a) : (b) )
  256. #define MAX(a, b) ((a) > (b) ? (a) : (b) )
  257. #define SETPT(pt, x, y)    (*(pt)).h = (x); (*(pt)).v = (y)
  258. #define SETRECT(r, left, top, right, bottom)    \
  259.                         SETPT(&TopLeft(*(r)), (left), (top)); \
  260.                         SETPT(&BotRight(*(r)), (right), (bottom))
  261. /* 
  262.  *    Useful macros for testing gestalt attribute responses
  263.  *
  264.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  265.  *    BTstQ which simply returns a non-zero value if the bit is set which
  266.  *    means the result could get lost if assigned to a short, for example.
  267.  *
  268.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  269.  *    bitnbr = 0 is the least significant bit.
  270.  */
  271. #define BTstBool(arg, bitnbr)    ((arg >> bitnbr) & 1)
  272. #define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))
  273.  
  274. #endif
  275.  
  276. /*-----------------------------------------------------------------------------------------
  277.     Global variables
  278. -----------------------------------------------------------------------------------------*/
  279. /*    The following global variables are initialized by StardardInitialization to
  280.  *    define the environnment.  This used to be a single SysEnvRec, but now,
  281.  *    all those variables defined in a SysEnvRec can be returned by Gestalt
  282.  *    (except sysVRefNum; see FindSysFolder).  Note that all the variables
  283.  *    below will be correctly initialized whether Gestalt is available or not;
  284.  *    the Gestalt glue handles this.
  285.  */
  286. extern short            gMachineType;            /* which machine this is */
  287. extern short            gSystemVersion;            /* System version number */
  288. extern short            gProcessorType;            /* which CPU this is */
  289. extern Boolean            gHasFPU;                /* true if machine has an FPU */
  290. extern short            gQDVersion;                /* major QD version #; 0 for original, 
  291.                                                     1 for color QD, 2 for 32-bit QD */
  292. extern short            gKeyboardType;            /* which type of keyboard is present */
  293. extern short            gAppleTalkVersion;        /* AppleTalk version number */
  294.         
  295. /*    These are also handled by Gestalt. gHasPMMU has no corresponding SysEnvRec
  296.  *    field, but it is handled by the glue, so we include it here for completeness.
  297.  *    gAUXVersion will be initialized with Gestalt if present, but correctly
  298.  *    set even if Gestalt is not available
  299.  */
  300. extern Boolean            gHasPMMU;                /* true if machine has a PMMU or equivalent */
  301. extern short            gAUXVersion;            /* major A/UX version number (0 if not present) */
  302.  
  303. /*    
  304.  *    gHasWaitNextEvent is set to TRUE if the Macintosh we are running on has
  305.  *    WaitNextEvent implemented. We can use this in our main event loop to
  306.  *    determine whether to call WaitNextEvent or GetNextEvent.
  307.  */
  308. extern Boolean            gHasWaitNextEvent;
  309.  
  310. /*
  311.  *    gAppResRef is the application’s resource file reference. I need to save
  312.  *    this since I can open other resource files. The current resource file is
  313.  *    always gAppResRef unless I momentarily set it to another file to read its
  314.  *    resources, and then immediately restore it back.
  315.  */
  316. extern short            gAppResRef;
  317.  
  318. /*
  319.  *    gInBackground is maintained by our osEvent handling routines. Any part of
  320.  *    the program can check it to find out if it is currently in the background.
  321.  */
  322. extern Boolean            gInBackground;            /* maintained by StandardInitialization
  323.                                                       and DoEvent */
  324.                                                       
  325. /*
  326.  *    gAppName holds the name of the application that's running. You can use if
  327.  *    for any purpose you'd like. It is also used by StandardAbout if it can't
  328.  *    find a string to use for the application name in a resource, so make sure
  329.  *    you call InitForStandardAbout if you are going to call StandardAbout. If you
  330.  *    call StandardInitialization, this is done for you.
  331.  */
  332. extern Str255            gAppName;
  333.  
  334. /*
  335.  *    gSignature holds the creator signature for the running application. It follows the
  336.  *    same rules as those for gAppName.
  337.  */
  338. extern OSType            gSignature;
  339.  
  340. /*
  341.  *    Initial values of these global variables are set to zero or FALSE by MPW's 
  342.  *    runtime initialization routines.  If the Utilities initialization routines
  343.  *    have been properly called, then gUtilitiesInited will be true.  If it is
  344.  *    not true, then the values of the above global variables are invalid.
  345.  */
  346. extern Boolean            gUtilitiesInited;
  347.  
  348. /*-----------------------------------------------------------------------------------------
  349.     Interface to routines
  350. -----------------------------------------------------------------------------------------*/
  351.  
  352. #ifdef __cplusplus
  353. extern "C" {
  354. #endif
  355.  
  356. short        CenteredAlert(short alertID, WindowPtr relatedWindow, ModalFilterProcPtr filter);
  357.             /* Given an Alert ID and a related window pointer, this routine will center
  358.                the alert on the same device as the related window.  If the related
  359.                window pointer is nil, then the alert will be centered on the device
  360.                that the alert would normally be placed if Alert was called directly. */
  361.  
  362. void        CenterRectInRect(Rect outerRect, Rect *innerRect);
  363.             /* Given two rectangles, this routine centers the second one within the first. */
  364.  
  365. Rect        CenterWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  366.             /* Given a window pointer and a related window pointer, this routine will
  367.                center the window on the same device as the related window.  If the
  368.                related window pointer is nil, then the window will be centered on the
  369.                device that the window already is.
  370.                WARNING: This routine may move or purge memory. */
  371.  
  372. void        CloseAnyWindow(WindowPtr window);
  373.             /* Closes the indicated window.  Does the right thing, taking into account
  374.                that the window may belong to a DA.
  375.                WARNING: An application window is closed via a CloseWindow call.  Use
  376.                            this call when you want to keep the storage for the window
  377.                         record.  (Compare against DisposeAnyWindow.) */
  378.  
  379. void        DisposeAnyWindow(WindowPtr window);
  380.             /* Disposes of the indicated window.  Does the right thing, taking into account
  381.                that the window may belong to a DA.
  382.                WARNING: An application window is closed via a DisposeWindow call.  Use
  383.                            this call when you want to free up the storage for the window
  384.                         record.  (Compare against CloseAnyWindow.) */
  385.  
  386. void        DeathAlert(short errResID, short errStringIndex);
  387.             /* Display an alert that tells the user an error occurred, then exit the
  388.                program. This routine is used as an ultimate bail-out for serious errors
  389.                that prohibit the continuation of the application. */ 
  390.  
  391. void        DeathAlertMessage(short errResID, short errStringIndex, short message);
  392.  
  393. void        ErrorAlert(short errResID, short errStringIndex);
  394.  
  395. void        ErrorAlertMessage(short errResID, short errStringIndex, short message);
  396.  
  397. OSErr        FindSysFolder(short *foundVRefNum, long *foundDirID);
  398.             /* FindSysFolder returns the (real) vRefNum, and the DirID of the current
  399.                system folder.  It uses the Folder Manager if present, otherwise
  400.                it falls back to SysEnvirons.  It returns zero on success, otherwise
  401.                a standard system error. */
  402.  
  403. Handle        GetAppIndResource(ResType theType, short index, OSErr *err);
  404.             /* GetAppIndResource gets a resource from the application's res file by index */
  405.  
  406. Handle        GetAppNamedResource(ResType theType, StringPtr name, OSErr *err);
  407.             /* GetAppNamedResource gets a resource from the application's res file by name */
  408.  
  409. Handle        GetAppResource(ResType theType, short theID, OSErr *err);
  410.             /* GetAppResource gets a resource from the application's res file by resource ID */
  411.  
  412. short        GetAUXVersion( void);
  413.             /* getAUXVersion -- Checks for the presence of A/UX by whatever means is
  414.                appropriate.  Returns the major version number of A/UX (i.e. 0 if A/UX 
  415.                is not present, 1 for any 1.x.x version 2 for any 2.x version, etc.
  416.                This code should work for all past, present and future A/UX systems. */
  417.  
  418. short        GetButtonVariant(ControlHandle ctl);
  419.                 /* This function returns which kind of button the control is.  This does more
  420.                 ** than GetCVariant in that it makes sure that the control is actually a
  421.                 ** button.  It does this by comparing the defProc against the known defProc
  422.                 ** for the various button types.  For 7.0, there is only one defProc for all
  423.                 ** variants, but for pre-7.0, there is one defProc value for each variant.
  424.                 ** The method below handles either case. */
  425.  
  426. OSErr        SimpleCanDialog(void);
  427.             /* Check to see if dialogs are allowed.  They may not be if AppleScript is
  428.                running the show. */
  429.  
  430. DialogPtr    GetCenteredDialog(short id, DialogPtr storage, WindowPtr relatedWindow, WindowPtr behind);
  431.             /* Given a dialog ID and a related window pointer, this routine will center
  432.                the dialog on the same device as the related window.  If the related
  433.                window pointer is nil, then the dialog will be centered on the device
  434.                that the dialog would normally be placed if GetNewDialog was called. */
  435.  
  436. WindowPtr    GetCenteredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  437.                               WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  438.             /* Given a window ID and a related window pointer, this routine will center
  439.                the window on the same device as the related window.  If the related
  440.                window pointer is nil, then the window will be centered on the device
  441.                that the window would normally be placed if GetNewWindow was called.  The
  442.                function is also passed the sizeInfo rect, which holds min and max size
  443.                information for the window.  (See GetSomeKindOfWindow.) */
  444.  
  445. Boolean     GetCheckOrRadio(DialogPtr dlgPtr, short itemNo);
  446.  
  447. long        GetGestaltResult(OSType gestaltSelector);
  448.             /* GetGestaltResult returns the result value from Gestalt for the specified
  449.                selector.  If Gestalt returned an error GetGestaltResult returns zero.  Use 
  450.                of this function is only cool if we don't care whether Gestalt returned an 
  451.                error.  In many casesyou may need to know the exact Gestalt error code so 
  452.                then this routine would be inappropriate. */
  453.  
  454. Point        GetGlobalMouse(void);
  455.             /* Returns the location of the mouse in local coordinates. It does this by
  456.                calling OSEventAvail(). */ 
  457.  
  458. Point        GetGlobalTopLeft(WindowPtr window);
  459.             /*     Given a window, this will return the top left point of the window’s port in
  460.                   global coordinates. Something this doesn’t include, is the window’s drag
  461.                   region (or title bar). This returns the top left point of the window’s
  462.                   content area only. */
  463.  
  464. long        GetKFreeSpace(short vRefNum);
  465.  
  466. Rect        GetMainScreenRect(void);
  467.  
  468. GDHandle    GetRectDevice(Rect globalRect);
  469.             /* Find the greatest overlap device for the given global rectangle.
  470.             ** This function assumes that you have a system that GDHandle can happen.
  471.             ** If you call this function on other QuickDraws, you will crash. */
  472.  
  473. Rect        GetRectDeviceRect(Rect globalRect);
  474.             /* Find the rect of the greatest overlap device for the given global rect. */
  475.  
  476. WindowPtr    GetSomeKindOfWindow(PositionWndProcPtr whatKind, short windID, Ptr storage,
  477.                                 Boolean vis, WindowPtr relatedWindow, WindowPtr behind,
  478.                                 Boolean inColor, Rect sizeInfo, long refCon);
  479.             /* Given a window positioning procedure pointer, a window ID and a window
  480.                pointer the window relates to, this function open a new window by either
  481.                a NewCWindow or a NewWindow call, depending on the value of inColor.  The
  482.                window will be opened invisible, independent of what the resource says.
  483.                Once the window is opened successfully, the positioning procedure is
  484.                called.  The positioning procedure is passed a pointer to the just-opened
  485.                invisible window,a pointer to the related window, and the sizeInfo rect.
  486.                The sizeInfo rect holds the minimum size in the upper-left point, and the
  487.                max size in the lower-left point.  It is up to the positioning procedure
  488.                to move the invisible window to the correct location on the correct device.
  489.                Once the positioning procedure returns, the window will be made visible if
  490.                so indicated by the resource. */
  491.  
  492. WindowPtr    GetStaggeredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  493.                                WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  494.             /* Given a window ID and a window pointer the window relates to, this function
  495.                will stagger the window’s rectangle before showing it on the proper screen.
  496.                This follows the Apple Human Interface Guidelines for where to place a
  497.                staggered window on the screen.  If the window is not closely associated
  498.                with another window, pass a nil for the window pointer of the related
  499.                window.  If you pass a nil, the window is simply displayed where the
  500.                resource would indicate.  The function is also passed the sizeInfo rect, which
  501.                holds min and max size information for the window.  (See GetSomeKindOfWindow.) */
  502.  
  503. void        GetSystemInfo(void);
  504.             /* This sets up some global variables for use by the utilities package and
  505.                your application.  If you call StandardInitialization, you don't need to
  506.                call this, as it will do it for you. */ 
  507.  
  508. TrapType    GetTrapType(short theTrap);
  509.             /* Returns the type (OSType or ToolType) of the trap. It does this by checking
  510.                the bits of the trap word. */ 
  511.  
  512. Rect        GetWindowContentRect(WindowPtr window);
  513.             /* Given a window pointer, return the global rectangle that encloses the
  514.                content area of the window. */
  515.  
  516. short        GetWindowCount(Boolean includeDAs, Boolean includeDLOGs, Boolean includeInvisibles);
  517.             /* This procedure counts the number of windows in the application plane.  You have the
  518.                choices of also counting DAs, DLOGs, and invisible windows in this count. */
  519.  
  520. GDHandle    GetWindowDevice(WindowPtr window);
  521.             /* Find the greatest overlap device for the given window. */
  522.  
  523. Rect        GetWindowDeviceRect(WindowPtr window);
  524.             /* Given a window pointer, find the device that contains most of the window
  525.                and return the device's bounding rectangle. */
  526.  
  527. Rect        GetWindowDeviceRectNMB(WindowPtr window);
  528.             /* Given a window pointer, find the device that contains most of the window
  529.                and return the device's bounding rectangle.  If this device is the main
  530.                device, then remove the menubar area from the rectangle. */
  531.  
  532. Rect        GetWindowStructureRect(WindowPtr window);
  533.             /* This procedure is used to get the rectangle that surrounds the entire
  534.                structure of a window.  This is true whether or not the window is visible.
  535.                If the window is visible, then it is a simple matter of using the bounding
  536.                rectangle of the structure region.  If the window is invisible, then the
  537.                strucRgn is not correct.  To make it correct, then window has to be moved
  538.                way off the screen and then made visible.  This generates a valid strucRgn,
  539.                although it is valid for the position that is way off the screen.  It still
  540.                needs to be offset back into the original position.  Once the bounding
  541.                rectangle for the strucRgn is obtained, the window can then be hidden again
  542.                and moved back to its correct location.  Note that ShowHide is used,
  543.                instead of ShowWindow and HideWindow.  HideWindow can change the plane of
  544.                the window.  Also, ShowHide does not affect the hiliting of windows. */
  545.   
  546. void        GlobalToLocalRect(Rect *aRect);
  547.  
  548. void        InitToolBox(void);
  549.  
  550. Boolean        IsAppWindow(WindowPtr window);
  551.             /* Returns TRUE if the windowKind of the window is greater than or equal to
  552.                userKind. If it is less, or the window is NIL, then return FALSE. */ 
  553.  
  554. Boolean        IsDAWindow(WindowPtr window);
  555.             /* Returns TRUE if the windowKind of the window is less than zero. If not, or
  556.                the window is NIL, then return FALSE. */ 
  557.  
  558. Boolean        IsScrollBar(ControlHandle ctl);
  559.             /* Returns TRUE if the control is a scrollbar. */
  560.  
  561. void        LocalToGlobalRect(Rect *aRect);
  562.  
  563. char        LockHandleHigh(Handle theHandle);
  564.             /* Does a MoveHHi on the handle and then locks it.  Also, the original state
  565.                of the handle is returned, so you can keep it and set the handle back to it's
  566.                original state with a HSetState call. */
  567.  
  568. short        NumToolboxTraps(void);
  569.             /* Determines the size of the Tool trap table. It does this by sampling a
  570.                couple of trap locations and seeing which, if any are Unimplemented. */ 
  571.  
  572. void        OutlineControl(ControlHandle button);
  573.  
  574. void         OutlineDialogItem(DialogPtr dlgPtr, short item);
  575.  
  576. void        PositionRectInRect(Rect outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio);
  577.             /* Given two rectangles, this routine positions the second within the first one
  578.                so that the it maintains the spacing specified the the horzRatio and vertRatio
  579.                parameters. In other words, to center an inner rectangle hoizontally, but
  580.                have its center be 1/3 from the top of the outer rectangle, call this
  581.                routine with horzRatio = FixRatio(1, 2), vertRatio = FixRatio(1, 3). */
  582.  
  583. void        PullApplicationToFront(void);
  584.             
  585. void        SelectButton(ControlHandle button);
  586.             /* Given the button control handle, this will cause the button to look as if it
  587.                has been clicked in. This is nice to do for the user if they type return or
  588.                enter to select the default item. */
  589.  
  590. void        SetCheckOrRadioButton(DialogPtr dlgPtr, short itemNo, short state);
  591.  
  592. Rect        StaggerWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  593.             /* This algorithm for staggering windows does quite a good job.  It also is
  594.                quite gnarly.  Here's the deal:
  595.                There are pre-designated positions that we will try when positioning a
  596.                window.  These slots will be tried from the upper-left corner towards the
  597.                lower-right corner.  If there are other windows in that slot, then we will
  598.                consider that slot taken, and proceed to the next slot.  A slot is
  599.                determined to be taken by checking a point with a slop area.  This slop
  600.                area is diamond-shaped, not simply rectangular.  If there is no other
  601.                visible window with an upper-left corner within the slopt diamond, then
  602.                we are allowed to position our window there.
  603.                The above rule holds true unless this forces the window to be partly
  604.                off the screen.  If the window ends up partly off the screen, then we give
  605.                up and just put it in the first slot. */
  606.  
  607. void        StandardAbout(short appNameStringID);
  608.             /* Shows a standard about box with the name of the application, its version
  609.                number, a copyright notice, and DTS credits. Most of this information is
  610.                taking from a standard DITL and the application’s 'vers' resource. The name
  611.                of the application is taken either from the 'STR ' resource passed in to
  612.                this routine, or from GetAppParms() if that resource doesn’t exist, or you
  613.                pass in -1. */ 
  614.  
  615. void        StandardInitialization(short callsToMoreMasters);
  616.             /* Initializes “gInBackGround” to FALSE. Makes the following InitXXX calls:
  617.                InitGraf(), InitFonts(), InitWindows(), InitMenus(), TEInit(),
  618.                InitDialogs(), InitCursor(). Brings application to front with 3 EventAvail
  619.                calls. Calls SysEnvirons to initialize “gMac”. Calls TrapExists() to
  620.                initialize “gHasWaitNextEvent”. */ 
  621.    
  622. void        StandardMenuSetup(short MBARID, short AppleMenuID);
  623.             /* Installs and draws the menus indicated by 'MBAR'(MBARID). Adds DA’s to the
  624.                menu indicated by AppleMenuID by calling AddResMenu. If the menuBar cannot
  625.                be created, the alert specified by rDeathAlert is displayed. */   
  626.  
  627. void         ToggleCheck(DialogPtr dlgPtr, short cChkItem);
  628.  
  629. Boolean        TrapExists(short theTrap);
  630.                 /* Returns TRUE if the trap exists (i.e., it’s callable without getting DS
  631.                    error 12) */ 
  632.  
  633. Boolean        WhichControl(Point mouseLoc, WindowPtr window, ControlHandle *ctlHit);
  634.                 /* Returns which visible control mouseLoc is within, independent of
  635.                    the state of the control.  Scrollbars that are inactive are not
  636.                    found by FindControl. */
  637.  
  638. void        ZoomToWindowDevice(WindowPtr window, short maxWidth, short maxHeight,
  639.                                short zoomDir, Boolean front);
  640.  
  641.  
  642.  
  643. pascal Boolean    AlertFilter(DialogPtr dlg, EventRecord *event, short *item);
  644. /* The alert filter makes sure that that the outline for the button gets
  645. ** redrawn.  This is important if balloon help is on, as the balloon window
  646. ** can overlap the outline of the button and leave a portion of it erased. */
  647.  
  648. pascal Boolean    KeyEquivFilter(DialogPtr dlg, EventRecord *event, short *item);
  649. /* The key equivalent filter allows you to assign key equivalents to dialog
  650. ** items.  Each item can have as many key equivalents as you wish.  You can
  651. ** also specify the exact state of the modifiers that you will or won't allow.
  652. ** The key equivalent information is stored in the resource fork, so the
  653. ** key equivalents can be easily localized.
  654. ** This code expects the key equivalents to be in item #2, which is a StatText
  655. ** item that is located so the text is outside of the dialog.  This allows us
  656. ** to put key equivalent information in the resource fork, so the key
  657. ** equivalents are localizable.
  658. **
  659. ** An example save changes before closing or quitting res source with
  660. ** keyEquiv info would look like:
  661. **
  662. ** resource 'DITL' (rYesNoCancel, purgeable) {
  663. **     {
  664. **         {71, 315, 91, 367}, Button     { enabled, "Save" },
  665. **         {0, -1000, 20, 2},  StaticText { disabled,
  666. **             "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004" },
  667. **         {71, 80, 91, 162},  Button { enabled, "Don’t Save" },
  668. **         {71, 244, 91, 302}, Button { enabled, "Cancel" },
  669. **         {11, 78, 61, 366},  StaticText { disabled,
  670. **             "Save changes to the document “^0” before ^1?" },
  671. **         {11, 23, 43, 55},        Icon { disabled, 2 }
  672. **     }
  673. ** };
  674. **
  675. ** The document name would be the string for param #0.
  676. ** The text "closing" or "quitting" would be the string for param #1.
  677. **
  678. ** The keyEquiv entry is item #2, which has a rect that pushes it out of the
  679. ** dialog.  The string info is interpreted as to what the key/modifier combo
  680. ** is, and what dialog item it relates to.
  681. **
  682. ** A single key equiv entry is 8 characters.  Entries are separated by commas.
  683. **
  684. ** If the first character of an entry is an =, then the next character is the 
  685. ** key.  If the first character isn't an =, then the first two characters are 
  686. ** the hex value of the key.  (Ex:  =S or =s for save, 1B for ESC.)
  687. **
  688. ** If the key pressed is the same as the key value for any of the entries, then 
  689. ** the next two characters are the hex value for which modifiers to test.  This
  690. ** modifier test value is anded with the modifier.  The result is then compared 
  691. ** to the value of the next two hex digits.  If they are equal, then the 
  692. ** modifiers are correct, as well as the key.  If this is so, we have a winner.
  693. **
  694. ** "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004"
  695. **
  696. ** The above string breaks down as follows:
  697. ** =S190001  =S  if event keypress is an S, check the modifier values
  698. **           19  check controlKey/optionKey/cmdKey
  699. **           00  all modifiers we are testing for should be false
  700. **           01  if above is true, keypress maps to item # 1
  701. ** =s190001  Same as =S, but lowercase
  702. ** =D190001  Same as =S, but maps to item #3
  703. ** =d190001  Same as =D, but lowercase
  704. ** =.190104  =.  if event keypress is a period, check the modifier values
  705. **           19  check controlKey/optionKey/cmdKey
  706. **           01  controlKey/optionKey should be false, cmdKey should be true
  707. **           04  if above is true, keypress maps to item # 4
  708. ** 1B190004  1B  if event keypress is an ESC, check the modifier values
  709. **           19  check controlKey/optionKey/cmdKey
  710. **           00  all modifiers we are testing for should be false
  711. **           04  if above is true, keypress maps to item # 4
  712. */
  713.  
  714. void            OffsetControl(ControlHandle ctl, short dx, short dy);
  715. /* This function is a convenient way to move a control a specified amount. */
  716.  
  717. void            DoDrawGrowIcon(WindowPtr window, Boolean horLine, Boolean verLine);
  718. /* This function draws the grow icon for the window in the specified manner.  You
  719. ** can clip out the horizontal or vertical line that is also drawn along with
  720. ** the grow icon, or you can have them draw. */
  721.  
  722. void            DoDrawControls(WindowPtr window, Boolean scrollBarsOnly);
  723. /* This function drawn all of the controls in a window, or just the scrollbar
  724. ** controls.  The reason for this function is that scrollbars are really
  725. ** tri-state, especially now with 7.0.  A scrollbar can be hilighted or not,
  726. ** or it can be drawn in a window that isn't the frontmost of the application
  727. ** plane.  DoDrawControls takes this third scrollbar state into consideration. */
  728.  
  729. void            DoDraw1Control(ControlHandle ctl, Boolean scrollBarsOnly);
  730. /* This function is where the work for scrollbar/control drawing is actually
  731. ** done.  DoDrawControls calls this function for each control in a window. */
  732.  
  733. ControlHandle    GetPopupCtlHandle(DialogPtr theDialog, short itemNum);
  734. /* GetPopupCtlHandle takes a dialog and its item number and (assuming it is a
  735. ** popup menu control) and returns the control handle for the popup. */
  736.  
  737. MenuHandle    GetPopupMenuHandle(ControlHandle popupCtl);
  738. /* GetPopupMenuHandle takes a popup control and returns the menu handle from
  739. ** the control. */
  740.  
  741. short    GetPopupCtlValue(DialogPtr theDialog, short popItem);
  742. /* GetPopupCtlValue returns value for the popup control. */
  743.  
  744. void    SetPopupCtlValue(DialogPtr theDialog, short popItem, short value);
  745. /* SetPopupCtlValue makes value the new value for the popup control. */
  746.  
  747. short    SmartInsMenuItem(MenuHandle theMenu, StringPtr theText, short section, short where);
  748. /* This is used to "intelligently" insert a menu item into a menu.  Pass it
  749. ** the menu to be modified, the text of the item being added, plus where the
  750. ** item is to be inserted.  The location to be inserted is described by two
  751. ** parameters:  section & where.
  752. **
  753. ** section:  Indicates which group of menu items you wish to add an item to.
  754. **           Menu item section 1 is all of the items before the first
  755. **           dividing line.  Menu item section 2 is all items after the
  756. **           first dividing line and before the second, and so on.  If you
  757. **           have no dividing lines, you have just 1 section so pass in 1.
  758. **
  759. ** where:    Indicates the item position relative to the section.  To add an
  760. **           item such that it is the first item in a section, pass in a 1.
  761. **           It will be added in front of the first item in the section.
  762. **
  763. **           NOTE:  You should never pass in a section or where parameter of 0.
  764. **
  765. ** Negative values for "where" are magic.  If where = kMenuItemTxtInsert, then
  766. ** it inserts the item alphabetically into the section.  A where of 
  767. ** kMenuItemNumInsert works the same as kMenuItemTxtInsert, except it treats
  768. ** the strings are numbers for comparison purposes.  If you want to add the
  769. ** item to the end of a section, use kMenuItemSectionEnd.
  770. **
  771. ** As a final goodie, SmartInsMenuItem returns the menu item # from the
  772. ** beginning of the menu, not section. */
  773.  
  774. short    CountMSections(MenuHandle theMenu);
  775. /* Return the number of menu sections.  The number of sections is equal to the
  776. ** number of dividing lines + 1. */
  777.  
  778. short    FindMenuItem(MenuHandle theMenu, StringPtr cmpTxt);
  779. /* Find the menu item number, given the text of the menu. */
  780.  
  781. OSErr    PersistFSSpec(PFSSpecPtr pfss);
  782. /* Do what is necessary to get an FSSpec to persist when saved to disk.  The parID
  783. ** will still be valid, along with the file name.  The part that isn't valid is
  784. ** the vRefNum.  This function converts the FSSpec's vRefNum to a volume name, or
  785. ** converts the volume name into a vRefNum.  An extended FSSpec is used.  The
  786. ** extension is, logically enough, a volume name.  If the FSSpec's vRefNum is non-0,
  787. ** then it fills in the volume name for that vRefNum.  If the vRefNum is 0, it then
  788. ** uses the volume name to generate a vRefNum.
  789. ** Prior to saving a PFSSpec to disk, call PersistFSSpec.  It will fill in the
  790. ** volume name.  After having read a PFSSpec from disk, set the vRefNum to 0 and
  791. ** then call PersistFSSpec.  It will fill in the vRefNum that corresponds to the
  792. ** volume name. */
  793.  
  794. StringPtr    PathNameFromDirID(long DirID, short vRefNum, StringPtr str);
  795. /* This function is straight out of tech note #238.  See this note for more info. */
  796.  
  797. void    InitQuickTime(void);
  798. /* Call this to generically initialize QuickTime.  It sets two globals:
  799. **     gQTVersion                    QuickTime version (0 means not available).
  800. **     gMovieControllerComponent    QuickTime movie controller component reference.
  801. */
  802.  
  803.  
  804. #ifdef __cplusplus
  805. }
  806. #endif
  807.  
  808. #endif
  809.